package com.example.student_manager_backend.service;

import com.example.student_manager_backend.entity.OperationLog;
import com.example.student_manager_backend.repository.OperationLogRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OperationLogService {

    @Autowired
    private OperationLogRepository operationLogRepository;

    @Transactional
    public OperationLog saveLog(OperationLog log) {
        return operationLogRepository.save(log);
    }

    public Page<OperationLog> findLogs(Specification<OperationLog> spec, Pageable pageable) {
        return operationLogRepository.findAll(spec, pageable);
    }

    public OperationLog findLogById(Long id) {
        return operationLogRepository.findById(id).orElse(null);
    }

    @Transactional
    public void deleteLog(Long id) {
        operationLogRepository.deleteById(id);
    }
} 